package app

import (
	"context"
	"os"
	"time"

	"gitee.com/zhangxinzx/egapp/pkg/server"
)

// Option is an application option.
type Option func(o *options)

// options is an application options.
type options struct {
	ctx         context.Context
	sigs        []os.Signal
	servers     []server.Server
	stopTimeout time.Duration
}

// Server with transport servers.
func Server(srv ...server.Server) Option {
	return func(o *options) { o.servers = srv }
}

// Signal with exit signals.
func Signal(sigs ...os.Signal) Option {
	return func(o *options) { o.sigs = sigs }
}

// Context with service context.
func Context(ctx context.Context) Option {
	return func(o *options) { o.ctx = ctx }
}

// StopTimeout with app stop timeout.
func StopTimeout(t time.Duration) Option {
	return func(o *options) { o.stopTimeout = t }
}
